#ifndef _ME2NETFOLDER_H
#define _ME2NETFOLDER_H

#include "clfc/clfc.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

#ifdef _WIN32

#include <direct.h>
#include <io.h>
#define S_ISDIR(x)	(x & _S_IFDIR) 
#define	mkdir(a,b)	_mkdir(a)		

#else

#include <dirent.h>

#endif

typedef struct {
	char	name[100];
	char	type[40];
	int	size;
	time_t	time;
	char	parent[1024];
} FileInfo;

typedef struct {
	int	recursive;
	LPCSTR	keyword;
	int	kwcase;
	time_t	time_from;
	time_t	time_to;
	int	size_from;
	int	size_to;
	int  	type;
} FileSearch;

#define NF_MIME_TYPE_MIN	1
#define NF_MIME_TYPE_MAX	3

#define CMP_FUNC(cmp_func)	int cmp_func(const void* a, const void* b);
CMP_FUNC(cmp_name)
CMP_FUNC(cmp_name_desc)
CMP_FUNC(cmp_size)
CMP_FUNC(cmp_size_desc)
CMP_FUNC(cmp_time)
CMP_FUNC(cmp_time_desc)

class ME2NetFolder {
	CLStr m_root;
	
public:
	ME2NetFolder() {}
	~ME2NetFolder() {}
	int Open(LPCSTR path, int bCreate=0); 
	unsigned long GetFolderProps(LPCSTR parent, int* num_file, int* num_folder=NULL) ;
	int GetAllFolder(LPCSTR parent,CLStrList& folderList);
	int GetFolderFile(LPCSTR parent, CLPtrList& folderList, CLPtrList& fileList, int (*cb)(const void*a, const void*b));
	int NewFolder(LPCSTR parent, LPCSTR folder);
	int CheckFolderName(LPCSTR folder);
	int IsFolder(LPCSTR folder);
	int CheckFolderPath(LPCSTR path);		

	int UploadFile(LPCSTR file, LPCSTR parent, LPCSTR name, int unzip=0);
	CLStr AbsolutePath(LPCSTR fid) { return m_root + fid;  }	 
	int Rename(CLStr& fid, LPCSTR dst);
	int Move(CLStr fid, CLStr dst, int bToOut=0);
	int Copy(CLStr fid, LPCSTR dst);
	int Del(CLStr fid);
	unsigned long Size(LPCSTR fid);
	CLStr FolderParent(CLStr& fid);	
	int SearchFolder(LPCSTR parent, FileSearch* fs, CLPtrList& folderList, CLPtrList& fileList) ;	
	
};


#endif

